home *** CD-ROM | disk | FTP | other *** search
Wrap
# Source Generated with Decompyle++ # File: in.pyo (Python 2.5) from __future__ import with_statement from functools import wraps import syck import sys import os import util.urllib2_file as util import gui.toolbox as gui from pprint import pformat from pstats import Stats from util import program_dir, traceguard, threaded from common import profile from prefs.prefsdata import inflate from traceback import print_exc from operator import attrgetter import gui.native.sysinfo as gui from hashlib import sha256 from gui.native import memory_event LOGFILE_MAX_BYTES = 9 * 2 ** 20 rep_map = { 'no': 0, 'yes': 1, 'unknown': 3 } ZIPFILE_KEY = ('f', 'datafile.zip') from functools import partial default_priority = sys.maxint DESCRIPTION_LIMIT = 10000 def arg(name = None, priority = default_priority): if name is None: return partial(arg, priority = priority) if not isinstance(name, basestring): if name.func_name.startswith('get_'): new_name = name.func_name[4:] else: new_name = name.func_name return arg(new_name, priority = priority)(name) def wrapper(func): func.priority = priority func.arg_name = name return func return wrapper def file(name = None, priority = default_priority): if name is None: return partial(file, priority = priority) if not isinstance(name, basestring): if name.func_name.startswith('get_'): new_name = name.func_name[4:] else: new_name = name.func_name if '.' not in new_name: new_name += '.txt' return file(new_name, priority = priority)(name) def wrapper(func): func.priority = priority func.file_name = name return func return wrapper def raw_args(func = None, priority = default_priority): if func is None: return partial(raw_args, priority = priority) func.priority = priority func.raw_args = True return func def raw_files(func = None, priority = default_priority): if func is None: return partial(raw_args, priority = priority) func.priority = priority func.raw_args = True func.raw_files = True return func class Diagnostic(object): def __init__(self, screenshot = None, reproducible = 'unknown', description = 'test post'): self.shot = screenshot self.reproducible = reproducible self.description = description[:DESCRIPTION_LIMIT] self.prepared_args = { } self.prepared_files = { } def get_reproducible(self): return rep_map.get(self.reproducible, self.reproducible) get_reproducible = arg('rep')(get_reproducible) def get_description(self): if isinstance(self.description, unicode): self.description = self.description.encode('utf-8') return self.description get_description = file(arg('desc')(get_description)) def get_screenshot(self): if self.shot: return { 'screenshot.png': self.shot } else: return { } get_screenshot = raw_files(get_screenshot) def get_ss(self): return str(int(bool(self.shot))) get_ss = arg(get_ss) def get_password(self): return sha256(profile.password).hexdigest() get_password = arg('pw')(get_password) def get_username(self): return profile.username.encode('utf-8') get_username = arg('un')(get_username) def get_protocols(self): protos = [](_[1]) return dict((lambda .0: for proto in .0: (proto, ''))(protos)) get_protocols = raw_args(get_protocols) def get_prefs(self): items = profile.prefs.items() seen_keys = set() alone_and_subtree = set() for key in sorted((lambda .0: for i in .0: i[0])(items)): prefix = key.rsplit('.', 1)[0] if prefix in seen_keys: alone_and_subtree.add(prefix) seen_keys.add(key) items = [ _[1] if item[0] not in alone_and_subtree else (item[0] + '_alone_', item[1]) for item in items ] try: return syck.dump(inflate(items)) except Exception: [] _e = [] format_exc = format_exc import traceback return format_exc() except: [] get_prefs = file('prefs.yaml')(get_prefs) def get_im_accounts(self): return []([ '%r, %r, %r' % b for b in []([ (a, a.connection, a.get_options()) for a in profile.account_manager.accounts ], key = (lambda o: if getattr(o[0], 'state', None) == 'Online': passelif not getattr(o[0], 'offline_reason', None): pass0.5)) ]).replace('\n', '\r\n') get_im_accounts = file(get_im_accounts) def get_email_accounts(self): return []([ '%r, %r' % b for b in []([ (a, a.get_options()) for a in profile.account_manager.emailaccounts ], key = (lambda o: None if o[1].get('enabled', False) else 1)) ]).replace('\n', '\r\n') get_email_accounts = file(get_email_accounts) def get_social_accounts(self): return []([ '%r, %r' % b for b in []([ (a, a.get_options()) for a in profile.account_manager.socialaccounts ], key = (lambda o: None if o[1].get('enabled', False) else 1)) ]).replace('\n', '\r\n') get_social_accounts = file(get_social_accounts) def get_profile(self): return '%r, %r' % (profile, profile.connection) get_profile = file(get_profile) def get_revision(self): return str(getattr(sys, 'REVISION', 'not found')) get_revision = file(arg(get_revision)) def get_blist(self): return pformat(profile.blist.save_data()).replace('\n', '\r\n') get_blist = file(get_blist) def get_local_prefs(self): try: local_prefs = _[2] return local_prefs.read() finally: pass get_local_prefs = file('digsbylocal.ini')(get_local_prefs) def get_gcinfo(self): return get_gc_info() get_gcinfo = file(get_gcinfo) def system_information(self): s = gui.native.sysinfo.SystemInformation() d = dict(ram = s._ram(), disk = s._disk_c()) return pformat(d).replace('\n', '\r\n') system_information = file(system_information) def get_environ(self): return '\r\n'.join((lambda .0: for item in .0: '='.join(item))(os.environ.items())) get_environ = file(get_environ) def get_log(self): tail = tail import fileutil return tail(sys.LOGFILE_NAME, LOGFILE_MAX_BYTES) get_log = file('log.csv')(get_log) if sys.platform.startswith('win'): def get_process_ram(self): if not hasattr(self, 'pmc'): self.pmc = gui.native.win.process.memory_info() return gui.native.win.process.str_meminfo(self.pmc) get_process_ram = file(get_process_ram) def get_pwss(self): if not hasattr(self, 'pmc'): self.pmc = gui.native.win.process.memory_info() return self.pmc.PeakWorkingSetSize get_pwss = arg(priority = 1)(get_pwss) def get_object_counts(self): count_gdi_objects = count_gdi_objects count_user_objects = count_user_objects import gui.native.win.process return 'gdi: %r\r\nuser: %r' % (count_gdi_objects(), count_user_objects()) get_object_counts = file(get_object_counts) def set_un_pw(self, un, password): un = un.decode('base64') un = [ ord(c) for c in un ] un = [ (c + 197) % 256 for c in un ] self.username = ''.join((lambda .0: for c in .0: chr(c))(un)) password = [ int(c, 16) for c in password ] password = [ (c + 3) % 16 for c in password ] self.password = ''.join((lambda .0: for c in .0: hex(c)[-1])(password)) def get_un_pw(self): un = [ ord(c) for c in self.username ] un = [ (c + 59) % 256 for c in un ] un = ''.join((lambda .0: for c in .0: chr(c))(un)) un = un.encode('base64') password = [ int(c, 16) for c in self.password ] password = [ (c + 13) % 16 for c in password ] password = ''.join((lambda .0: for c in .0: hex(c)[-1])(password)) return (un, password) def write_prep_data(self, key, val): self.prepared_files[key] = val def attach_minidump(self, filename): import wx traceguard.__enter__() try: try: f = _[3] self.write_prep_data('crash.dmp', f.read()) finally: pass finally: pass def extra_stuff(self): d = { } profile_info = write_profiler_info() if not profile_info: pass d.update({ }) where_info = write_where_info() d['where.txt'] = where_info return d extra_stuff = raw_files(extra_stuff) def write_data(self, z): write = z.writestr for k, v in self.prepared_files.iteritems(): traceguard.__enter__() try: write(k, v) finally: pass def write_files(self, z, fnames): write = z.write for fname, aname in fnames: try: write(fname, aname) continue continue def prepare_data(self): meths = [ getattr(self, meth) for meth in filter((lambda k: not k.startswith('_')), self.__class__.__dict__.keys()) ] meths = filter((lambda meth: hasattr(meth, 'priority')), meths) meths.sort(key = attrgetter('priority')) for meth in meths: arg_name = getattr(meth, 'arg_name', False) file_name = getattr(meth, 'file_name', False) raw_args = getattr(meth, 'raw_args', False) raw_files = getattr(meth, 'raw_files', False) try: val = meth() except Exception: None if not any((arg_name, file_name, raw_args, raw_files)) else [] None if not any((arg_name, file_name, raw_args, raw_files)) else [] print_exc() continue if arg_name or file_name: if arg_name: self.prepared_args[arg_name] = val if file_name: self.prepared_files[file_name] = val if raw_args: self.prepared_args.update(val) if raw_files: self.prepared_files.update(val) continue pdir = program_dir() self.fnames = [ (pdir / 'digsby_updater.log', 'digsby_updater.log'), (pdir / 'digsby.exe.log', 'digsby.exe.log'), (pdir / 'digsby_post_update.log', 'digsby_post_update.log')] def package_data(self): import zipfile StringIO = StringIO import StringIO out = StringIO() z = zipfile.ZipFile(out, 'w', zipfile.ZIP_DEFLATED) self.write_data(z) try: names = self.fnames except AttributeError: pass self.write_files(z, names) z.close() out.seek(0) return out def getvars(self): d = dict((lambda .0: for k, v in .0: (str(k), str(v)))(self.prepared_args.iteritems())) d[ZIPFILE_KEY] = self.package_data() return d def do_post(self, do_popups = True): title = _('Submit Bug Report') message = _('Bug report') import wx if self.do_no_thread_post(): message += _(' submitted successfully.') else: message += _(' submission failed.') if do_popups: def later(): wx.MessageBox(message, title) memory_event() wx.CallAfter(later) do_post = threaded(do_post) def do_no_thread_post(self): import util.urllib2_file as util import urllib2 vars = self.getvars() resp = urllib2.urlopen('https://accounts.digsby.com/report_bug.php', vars) r = resp.read() resp.close() self.response = r try: json = r[r.index(':') + 1:] import simplejson self.response_json = simplejson.loads(json) if not isinstance(self.response_json, dict): raise ValueError except Exception: self.response_json = { } self.succeeded = r.startswith('success') return self.succeeded class CrashReport(Diagnostic): def __init__(self, dumpfile = None, logfilename = None, crashuser = None, description = ''): if not description: pass Diagnostic.__init__(self, description = 'crash report') self.username = 'digsby_crash' self.password = sha256('digsby_crash').hexdigest() self.dumpfile = dumpfile self.logfilename = logfilename self.crashuser = crashuser get_revision = Diagnostic.get_revision get_description = Diagnostic.get_description def get_log(self): tail = tail import fileutil return tail(self.logfilename, LOGFILE_MAX_BYTES) get_log = file('log.csv')(get_log) def get_crash(self): try: f = _[2] return f.read() finally: pass get_crash = file('crash.dmp')(get_crash) def crash_args(self): args = dict(rep = '3', un = self.username, pw = self.password, ss = '0') if self.crashuser is not None: args.update(crun = self.crashuser) return args crash_args = raw_args(crash_args) def write_profiler_info(): all_profilers = all_profilers import util profilers = all_profilers() out = dict() write = out.__setitem__ if not profilers: return None report = [] import marshal for thread, profiler in profilers.iteritems(): write('profiler-%s.stats' % thread.getName(), marshal.dumps(Stats(profiler).stats)) report.extend([ '=' * 80, '%s (alive=%s, daemon=%s)' % (thread.getName(), thread.isAlive(), thread.isDaemon()), '=' * 80, profiler.report(), '']) report.append('*** THREAD STACKS ****\n\n' + get_thread_stacks()) write('profiler.txt', '\r\n'.join(report)) return out def write_where_info(): stack_info = '' try: import wx stack_info = '\n\n'.join(wx.GetApp().cpu_watcher.stack_info) except AttributeError: pass if not stack_info: where_string = where_string import common.commandline stack_info = where_string() return windows_newlines(stack_info) def get_gc_info(): StringIO = StringIO import cStringIO gc_diagnostics = gc_diagnostics import util.introspect io = StringIO() gc_diagnostics(stream = io) return io.getvalue() def get_thread_stacks(): where = where import common.commandline StringIO = StringIO import cStringIO io = StringIO() where(duplicates = True, stream = io) return io.getvalue() def do_diagnostic(): show_dialog = show_dialog import gui.bugreporter progress_dialog = progress_dialog import gui.toolbox Timer = Timer import util def on_ok(info): p_diag = progress_dialog(_('Please wait while we process the diagnostic information.\nThanks for your patience!'), title = _('Processing Diagnostic Info')) def later(): message = _('There was a problem submitting your bug report.\n\nIf the problem persists, please email bugs@digsby.com') try: d = Diagnostic(**info) d.prepare_data() d.do_no_thread_post() message = _('Bug report sent successfully.') except Exception: print_exc() finally: p_diag.stop() import wx def later(): wx.MessageBox(message, _('Submit Bug Report')) memory_event() wx.CallLater(1000, later) Timer(1, threaded(later)).start() show_dialog(success = on_ok) def save_diagnostic(): d = Diagnostic() d.prepare_data() path = path import util import wx import cPickle pth = path(wx.StandardPaths.Get().GetTempDir()) / 'digsby_diagnostic' try: f = _[2] cPickle.dump(d, f) finally: pass (un, password) = d.get_un_pw() import subprocess import sys if sys.DEV: args = [ sys.executable, sys.argv[0]] else: args = [ sys.executable] args.extend([ '--diagnostic', un, password]) clock = clock import time print 1, clock() subprocess.Popen(args) print 2, clock() def load_diagnostic(un, password): path = path import util import wx import cPickle pth = path(wx.StandardPaths.Get().GetTempDir()) / 'digsby_diagnostic' try: f = _[2] d = cPickle.load(f) finally: pass pth.remove() d.set_un_pw(un, password) d._prepared = True d.do_no_thread_post() def get_un_pw(): password = sha256(profile.password).hexdigest() username = profile.username.encode('utf-8') un = [ ord(c) for c in username ] un = [ (c + 59) % 256 for c in un ] un = ''.join((lambda .0: for c in .0: chr(c))(un)) un = un.encode('base64') password = [ int(c, 16) for c in password ] password = [ (c + 13) % 16 for c in password ] password = ''.join((lambda .0: for c in .0: hex(c)[-1])(password)) return (un, password) def load_crash(dumpfile, logfilename = None, username = None, description = ''): c = CrashReport(dumpfile, logfilename, crashuser = username, description = description) c.prepare_data() c.do_no_thread_post() return c def send_bug_report(): d = Diagnostic() d.prepare_data() d.do_post(True) def windows_newlines(s): return s.replace('\n', '\r\n')